﻿using Microsoft.Extensions.DependencyInjection;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Configuration;

namespace DAL
{
    /// <summary>
    /// 配置扩展
    /// </summary>
    public static class DalServiceExtensions
    {
        /// <summary>
        /// 向服务容器注册 DAL 层的服务
        /// </summary>
        public static IServiceCollection AddDalServices(this IServiceCollection services, IConfiguration configuration)
        {
            // 注册 AppDbContext
            services.AddDbContext<AppDbContext>(options =>
            {
                // 从配置文件读取连接字符串
                string connectionString = configuration.GetConnectionString("SqlServer");
                options.UseSqlServer(connectionString);
            });

            services.AddScoped<JurisdictionDal>();
            services.AddScoped<BiCustomerDal>();
            services.AddScoped<UsersDal>();
            services.AddScoped<BiSupplierDal>();
            services.AddScoped<OmPurchaseOrderDal>();
            services.AddScoped<GoodsTypeDal>();
            services.AddScoped<BiProductDal>();
            services.AddScoped<SysAttachmentDal>();
            services.AddScoped<BiWarehouseDal>();
            services.AddScoped<WhBatchDal>();
            services.AddScoped<WhInventoryDal>();
            services.AddScoped<WhLocationDal>();
            services.AddScoped<WhInboundDal>();
            services.AddScoped<OmSalesOrderDal>();
            services.AddScoped<OmSalesOrderDetailDal>();
            services.AddScoped<OmSalesReturnDal>();
            services.AddScoped<OmSalesReturnDetailDal>();
            services.AddScoped<WhStockTakeDal>();
            services.AddScoped<WhStockTakeDetailDal>();
            services.AddScoped<WhTransferDal>();
            services.AddScoped<WhTransferDetailDal>();
            services.AddScoped<WhOutboundDal>();
            services.AddScoped<WhOutboundDetailDal>();
            services.AddScoped<InventoryInquiryDal>();

            return services;
        }
    }
}
